﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GovernmentOfficeProject.LevelDataAccess;
using GovernmentOfficeProject.LevelDataAccessModel;

namespace GovernmentOfficeProject.LevelBusinessLogic
{
    public class BLL_RoleManager
    {
        public BLL_RoleManager()
        {

        }

        public List<Entity_USER_Role> getRoleList()
        {
            try
            {
                return new DAL_USER_Role().getRoleList();
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        public List<Entity_USER_Role> getRoleListByUser(Entity_USER_User userEntity)
        {
            try
            {
                if (userEntity!=null)
                {
                    return new DAL_USER_Role().getRoleListByUserID(userEntity.UserID);
                }
                return new List<Entity_USER_Role>();
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        public bool addRole(Entity_USER_Role roleEntity)
        {
            try
            {
                return new DAL_USER_Role().addRole(roleEntity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public List<Entity_USER_Role> getRoleByCondition(Entity_USER_Role roleEntity)
        {
            try
            {
                return new DAL_USER_Role().getRoleListByRoleEntity(roleEntity);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        public Entity_USER_Role getRoleByRoleID(decimal roleID)
        {
            try
            {
                return new DAL_USER_Role().getRoleByRoleID(roleID);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        public bool updateRoleByRoleIDAndEntity(decimal roleID, Entity_USER_Role roleEntity)
        {
            try
            {
                return new DAL_USER_Role().updateRoleByRoleID(roleID, roleEntity);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        public bool deleteRoleByRoleID(decimal roleID)
        {
            try
            {
                return new DAL_USER_Role().deleteRoleByRoleID(roleID);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        //获取用户组下的用户数量
        public int getUserCountByRoleID(decimal roleID)
        {
            try
            {
                return new DAL_USER_UserRole().getUserCountByRoleID(roleID);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }

        //根据用户ID获取ROLElist
        public List<Entity_USER_Role> getRoleListByUserID(decimal userID)
        {
            try
            {
                return new DAL_USER_Role().getRoleListByUserID(userID);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
    }
}
